package com.xpalive;


import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;

@SpringBootApplication
@Slf4j
@AllArgsConstructor
public class Application implements ApplicationListener<ApplicationReadyEvent> {

    private final ServerProperties serverProperties;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
        int serverPort = Optional.ofNullable(serverProperties.getPort()).orElse(8080);
        String contextPath = serverProperties.getServlet().getContextPath();
        log.info(String
            .format("swagger-ui:http://localhost:%d%s/swagger-ui.html", serverPort, contextPath));
        log.info(String.format("doc-ui:http://localhost:%d%s/doc.html", serverPort, contextPath));
    }

}
